﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Node
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {

                List<Thread> threads = new List<Thread>();
                List<System.Threading.Thread> st = new List<System.Threading.Thread>();
                int coreCount =
                    new System.Management.ManagementObjectSearcher("Select * from Win32_Processor").Get()
                        .Cast<ManagementBaseObject>()
                        .Sum(item => int.Parse(item["NumberOfCores"].ToString()));
                Console.WriteLine("Threads count " + coreCount);
                for (int i = 0; i < coreCount; i++)
                {
                    var thread = new Thread();
                    threads.Add(thread);
                    System.Threading.Thread t = new System.Threading.Thread(thread.Run);
                    st.Add(t);
                    t.Priority = System.Threading.ThreadPriority.Lowest;
                    t.Start();

                }
                while (true)
                    System.Threading.Thread.Sleep(1000);
            }
            catch (Exception ex)
            {
                    if (ex.Message == new OutOfMemoryException().Message)
                        Application.Restart();
                
            }
        }
    }


}
